Page({
    data: {
      currentTab: 0,
      height: 0,


      list: [],
      list2: [],
      list3: [],
      loading1: true,
      loading2: true,
      loading3: true,
      params: {
        pageNum: 1,
        pageSize: 999999,
        option: -1
      },
      count: 0,
      count2: 0,
      count3: 0,
      num: 0
    },

    onLoad (options) {
      this.getHeight()
      this.setData({
        num: options.num
      })
    },
    //获取屏幕高度
    getHeight() {
      var _this = this
      wx.getSystemInfo({
        success: function (res) {
          let clientHetght = res.windowHeight
          let clientWidth = res.windowWidth
          let ratio = 750 / clientWidth
          let height = clientHetght * ratio - 374
          _this.setData({
            height: height
          })
        },
      })
    },

    // 头部点击切换
    tabClick (e) {
      console.log(e)
      var cur = e.currentTarget.dataset.curr
      var options = "params.option"
      this.setData({
        currentTab: cur,
        [options]: cur == 0 ? -1 : cur == 1 ? 0: 1
      })

      if (this.data.params.option == -1) {
        if (this.data.loading1 == false) {
          return false
        }else{
          this.getList(this.data.params)
        }
      }
      if (this.data.params.option == 0) {
        if (this.data.loading2 == false) {
          return false
        }else{
          this.getList(this.data.params)
        }
      }

      if (this.data.params.option == 1) {
        if (this.data.loading2 == false) {
          return false
        }else{
          this.getList(this.data.params)
        }
      }
    },
    // tab滑动切换
    switchTab (event) {
      var cur = event.detail.current
      var options = "params.option"
      this.setData({
        currentTab: cur,
        [options]: cur == 0 ? -1 : cur == 1 ? 0 : 1
      })

      if (this.data.params.option == -1) {
        if (this.data.loading1 == false) {
          return false
        } else {
          this.getList(this.data.params)
        }
      }
      if (this.data.params.option == 0) {
        if (this.data.loading2 == false) {
          return false
        } else {
          this.getList(this.data.params)
        }
      }

      if (this.data.params.option == 1) {
        if (this.data.loading3 == false) {
          return false
        } else {
          this.getList(this.data.params)
        }
      }
    },

    //获取书币列表
    getList (params) {
      wx.showLoading({
        title: '加载中',
      })
      var _this = this
      wx.request({
        url: 'https://devapi.xiaoshitimebank.com/user/sdx/sdx/sdxScoreRecord/list/auth',
        data: params,
        method: 'POST',
        header: {
          "content-type": "application/x-www-form-urlencoded; charset=UTF-8",
        "token" : wx.getStorageSync('token'),
          "uid" : wx.getStorageSync('uuid')
        },
        success: (res) => {
        if (res.data.code == 200) {
          wx.hideLoading()
          if (params.option == -1) {
            var arr = res.data.data.resultList
            _this.setData({
              list: arr,
              count: res.data.data.totalCount
            })
            _this.setData({
              loading1: false
            })
          }

          if (params.option == 0) {
            var arr = res.data.data.resultList
            _this.setData({
              list2: arr,
              count2: res.data.data.totalCount
            })
            _this.setData({
              loading2: false
            })
          }

          if (params.option == 1) {
            var arr = res.data.data.resultList
            _this.setData({
              list3: arr,
              count3: res.data.data.totalCount
            })
            _this.setData({
              loading3: false
            })
          }
        }else{
          wx.showToast({
            title: res.data.msg,
            icon: 'none'
          })
        }
      }
      })
    },


    onShow () {
      this.getList(this.data.params)
    }
})
